﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Cannon : MonoBehaviour
{

    public Rigidbody2D ball;
    public Transform ballPoint;
    public Animator anim;

    public float attackCD;
    public float nextAttack;
    public float ballSpeed;
    // Start is called before the first frame update
    void Start()
    {
        anim = gameObject.GetComponent<Animator>();
    }

    // Update is called once per frame
    void Update()
    {   
        if (Time.time > nextAttack)
        {
            anim.SetTrigger("attack");
            nextAttack = Time.time + attackCD;
            var ballInstance =  Instantiate(ball,ballPoint.position,ballPoint.rotation);
            ballInstance.velocity = new Vector2(-transform.localScale.x * ballSpeed,0);
        }
    }

}
